package te2;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class  sa{
	@SuppressWarnings("unused")
	public static void main(String[] args) {

		String dStr = "2016-8-7 13:57:27";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		try {
			if (dStr == null) {
				System.out.println("/*/*");
			} else {
				Date date = sdf.parse(dStr);
				long longDate = date.getTime();
				String re = gettime(longDate);
				System.out.println(re + "**");
			}

		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	public static String gettime(long dateTimeStamp) {
		long minute = 1000 * 60;
		long hour = minute * 60;
		long day = hour * 24;
		long month = day * 30;

		long now = new Date().getTime();
		long diffValue = now - dateTimeStamp;
		if (diffValue < 0) {
			return "";
		}

		int monthC = (int) Math.abs(diffValue / month);
		int weekC = (int) (diffValue / (7 * day));
		int dayC = (int) (diffValue / day);
		int hourC = (int) (diffValue / hour);
		int minC = (int) (diffValue / minute);
		String result;
		if (monthC >= 1) {
			if (monthC <= 12) {
				result = monthC + "����ǰ";
			} else {
				DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				Calendar calendar = Calendar.getInstance();
				calendar.setTimeInMillis(dateTimeStamp);
				result = formatter.format(calendar.getTime());
			}
		} else if (weekC >= 1) {
			result = weekC + "��ǰ";
		} else if (dayC >= 1) {
			result = dayC + "��ǰ";
		} else if (hourC >= 1) {
			result = hourC + "Сʱǰ";
		} else if (minC >= 1) {
			result = minC + "����ǰ";
		} else{
			
		}
			result = "�ո�";
		return result;

	}

}
